using UnityEngine;
using System;




public class SABattleCommandManager : Singleton< SABattleCommandManager > 
{

	SACreatureFightCommand command;
	SACreatureFightCommand petCommand;

	bool waitCommand = true;
	bool waitPetCommand = true;

	void Awake ()
	{
		mInstance = this;
		
	}

	public void updateCommand()
	{

	}


	public void runCommand()
	{
		if ( SABattleManager.instance.checkContralStage( (int)SABattleContralStage.COMMAND ) )  
		{
			command.TargetIndex = (byte)SABattleCreautreManager.instance.mainIndex;
			command.TargetRow = (byte)SABattleSessionRow.UNDER;
			command.Type = (byte)SABattleSessionCommandType.ESCAPE;
		}
		else if ( SABattleManager.instance.checkContralStage( (int)SABattleContralStage.PETCOMMAND ) )  
		{
			petCommand.TargetIndex = (byte)SABattleCreautreManager.instance.mainPetIndex;
			command.TargetRow = (byte)SABattleSessionRow.UP;
			command.Type = (byte)SABattleSessionCommandType.ESCAPE;
		}

		sendCommandMsg();

		SABattleManager.instance.changeContralStage( (int)SABattleContralStage.WAIT );
	}

	public void atkCommand( SABattleSessionCommand c )
	{
		if ( SABattleManager.instance.checkContralStage( (int)SABattleContralStage.COMMAND ) )  
		{
			command.TargetIndex = c.Index;
			command.TargetRow = c.Row;
			command.Type = (byte)SABattleSessionCommandType.ATTACK;
		}
		else if ( SABattleManager.instance.checkContralStage( (int)SABattleContralStage.PETCOMMAND ) )  
		{
			petCommand.TargetIndex = c.Index;
			petCommand.TargetRow = c.Row;
			petCommand.Type = (byte)SABattleSessionCommandType.ATTACK;
		}

		sendCommandMsg();

		SABattleCreautreManager.instance.enableEnemiesTargets( false );

		SABattleManager.instance.changeContralStage( (int)SABattleContralStage.WAIT );
	}


	void sendCommandMsg()
	{
		GameNetMessage.SEND_MSG_BATTLE_COMMAND msg = new GameNetMessage.SEND_MSG_BATTLE_COMMAND();
		msg.initNetHead();

		msg.Command = command;
		msg.PetCommand = petCommand;

		GameSocketManager.instance.sendMsg( msg );
	}

}
